<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Swoole\Process\Pool;

class TcpProcess extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'tcp:process';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //
        $pool=new Pool(2,SWOOLE_IPC_SOCKET);
        $pool->on('WorkerStart',function($pool,$workerId){
            echo "worker#{$workerId} is started\n";
        });

        $pool->on("Message",function($pool,$message){
            echo "Message {$message}\n";
        });
        $pool->listen('127.0.0.1',8089);
        $pool->start();
    }
}
